package org.foj.dao.impl;

import org.appfuse.dao.hibernate.GenericDaoHibernate;
import org.foj.dao.CommentDao;
import org.foj.model.Comment;

import java.util.List;

/**
 * @author jeremy anderson
 */
public class CommentDaoImpl extends GenericDaoHibernate<Comment, Long> implements CommentDao {

  public CommentDaoImpl() {
    super(Comment.class);
  }

  @Override
  @SuppressWarnings("unchecked")
  public List<Comment> getCommentsByIssueId(Long issueId) {
    return getHibernateTemplate().find("from Comment where issue_id = ?", issueId);
  }

  public void deleteAllCommentsForIssueId(Long issueId) {
    List<Comment> comments = getCommentsByIssueId(issueId);

    for (Comment comment : comments) {
      getHibernateTemplate().delete(comment);
    }
  }
}
